package com.suyl.markbfbc.suanfa;

/**
 * 最大子列和问题
 */
public class ZuiDaZiLieHe {
    static int[] arrs = new int[]{-4, 9, -2, 4, -3};


    public static void main(String[] args) {
        int thisnums = 0;
        int maxsnums = 0;
        for (int i = 0; i < arrs.length; i++) {
            thisnums += arrs[i];
            if (thisnums > maxsnums) {
                maxsnums += thisnums;
            } else if (thisnums < 0) {
                thisnums = 0;
            }
        }
        System.out.println(maxsnums);
    }
}
